package other;

import javax.swing.tree.TreeNode;
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

import static java.lang.Integer.reverse;

/**
 * @Description 多个apk对应的txt 合成一个 api.txt  (apiList.txt是每行对应的apk名称)
 * @Author chenyingbi
 * @Date 2020/06/22 12:50
 */
public class apk2 {
    public static void main(String[] args) {


        try (
                FileWriter fw = new FileWriter("C:\\Users\\chenyb\\Desktop\\api.txt");
                FileWriter fw2 = new FileWriter("C:\\Users\\chenyb\\Desktop\\apiList.txt")
        ) {

            // 1. 提取api特征
            File file = new File("C:\\Users\\chenyb\\Desktop\\api");
            if (file.exists()) {
                File[] apis = file.listFiles();
                System.out.println(apis);
                StringBuffer apiList = new StringBuffer();
                for (File api : apis) {
                    System.out.println("-》 正在遍历api: " + api.getName());
                    apiList.append(api.getName() + "\n");

                    StringBuffer buffer = new StringBuffer();
                    BufferedReader bf = new BufferedReader(new FileReader(api.getAbsolutePath()));
                    String s = null;
                    while ((s = bf.readLine()) != null) {//使用readLine方法，一次读一行
                        buffer.append(s.trim());
                    }
                    String xml = buffer.toString();

                    fw.write(xml + "\n");
                    System.out.println("《- 遍历结束，保存完成");
                }

                fw2.write(apiList.toString());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void merge() {

    }

}
